-- @owner: opentestcase023
-- @date: 2022/02/24
-- @testpoint: 在清空src表之后触发向des表中插入计数器数字   each statement

--step1:建表;expect:成功
drop table if exists t_trigger_src_52 cascade;
drop table if exists t_trigger_des_52 cascade;
drop sequence if exists trigger_des_seq1 cascade;
create table t_trigger_src_52(id1 int, id2 int, id3 int) with (storage_type=ustore);
create table t_trigger_des_52(id1 int, id2 int, id3 int) with (storage_type=ustore);
create sequence trigger_des_seq1;

--step2:在清空src表之后触发向des表中插入计数器数字 each statement;expect:成功
create or replace function tri_truncate_func() returns trigger as
$$
declare
begin
insert into t_trigger_des_52 values(nextval('trigger_des_seq1'),nextval('trigger_des_seq1'),nextval('trigger_des_seq1'));
return new;
end
$$ language plpgsql;
/
drop trigger if exists truncate_trigger on t_trigger_src_52;
create trigger truncate_trigger after truncate on t_trigger_src_52
for each statement
execute procedure tri_truncate_func();
/
select * from t_trigger_des_52 order by id1;
insert into t_trigger_src_52 values(1,1,1),(2,2,2),(3,3,3);
select * from t_trigger_src_52 order by id1;
select * from t_trigger_des_52 order by id1;
truncate table t_trigger_src_52;
select * from t_trigger_src_52 order by id1;
select * from t_trigger_des_52 order by id1;

--step3:清理环境;expect:成功
drop trigger if exists truncate_trigger on t_trigger_src_52;
drop table if exists t_trigger_src_52 cascade;
drop table if exists t_trigger_des_52 cascade;
drop sequence if exists trigger_des_seq1 cascade;
drop function if exists tri_truncate_func;